package com.itheima.controller;

import com.itheima.common.PaginationVO;
import com.itheima.common.Result;
import com.itheima.entity.Advimg;
import com.itheima.service.AdvimgService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/ydd_advimg")
@RequiredArgsConstructor
public class AdvimgController {
    private final AdvimgService advimgService;

    @GetMapping("/list")
    public Result<PaginationVO<Advimg>> page(String advposdesc, String advimgpos,
                                            @RequestParam(defaultValue = "1") String page,
                                            @RequestParam(defaultValue = "10") String limit) {
        //记录日志
        log.info("分页查询，参数：{},{},{},{}", page, limit, advposdesc,advimgpos);
        //调用业务层分页查询功能
        PaginationVO<Advimg> pages = advimgService.page(page, limit, advposdesc,advimgpos);
        //响应
        return Result.success(pages);
    }


    @PostMapping("/add")
    public Result<?> addAdvimg(@RequestBody Advimg adv) {
        advimgService.addAdvimg(adv);
        return Result.success();
    }

    @PostMapping("/update")
    public Result<?> updateAdvpos(@RequestBody Advimg adv) {
        advimgService.updateAdvimg(adv);
        return Result.success();
    }

    @GetMapping("/rowInfo")
    public Result<Advimg> rowInfoAdvpos(Integer id) {
        Advimg adv = advimgService.rowInfoAdvpos(id);
        return Result.success(adv);
    }

    @GetMapping("/del")
    public Result<?> deleteAdvimg(Integer id) {
        advimgService.deleteAdvimg(id);
        return Result.success();
    }
}
